<?php

class UtilTester extends TestRunner{
	
	public function test_01_base64UrlEncode(){
		//===============================================================
		$input = "";
		$expected = "";
		
		$actual = Util::base64UrlEncode($input);
		
		self::assertEqual($actual, $expected);

		//===============================================================
		$input = "1";
		$expected = "MQ";
		
		$actual = Util::base64UrlEncode($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "2";
		$expected = "MQ";
				
		$actual = Util::base64UrlEncode($input);
		
		self::assertNotEqual($actual, $expected);
	}
	
	public function test_02_base64UrlDecode(){
		//===============================================================
		$input = "";
		$expected = "";
		
		$actual = Util::base64UrlDecode($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "MQ";
		$expected = "1";
		
		$actual = Util::base64UrlDecode($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "MQ";
		$expected = "2";
		
		$actual = Util::base64UrlDecode($input);
		
		self::assertNotEqual($actual, $expected);
		
		//===============================================================
		$input = "M_";
		$expected = "3";
		
		$actual = Util::base64UrlDecode($input);
		
		self::assertEqual($actual, $expected);
	}
	
	public function test_03_ifSet(){
		//===============================================================
		$inputx = "";
		$expected = "";
		
		$actual = Util::ifset($inputx);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = "a";
		$expected = "a";
		
		$actual = Util::ifset($inputx);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = null;
		$expected = null;
		
		$actual = Util::ifset($inputx);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = false;
		$expected = false;
		
		$actual = Util::ifset($inputx);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = true;
		$expected = true;
		
		$actual = Util::ifset($inputx);
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = true;
		$expected = true;
		
		$actual = Util::ifset($inputx, "NotUsed");
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputx = null;
		$expected = "Used";
		
		$actual = Util::ifset($inputx, "Used");
				
		self::assertEqual($actual, $expected);
	}
	
	public function test_04_toBoolean(){
		//===============================================================
		$input = "true";
		$expected = true;
		
		$actual = Util::toBoolean($input);
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "false";
		$expected = false;
		
		$actual = Util::toBoolean($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "off";
		$expected = false;
		
		$actual = Util::toBoolean($input);
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = "Valid";
		$expected = true;
		
		$actual = Util::toBoolean($input);
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = true;
		$expected = true;
		
		$actual = Util::toBoolean($input);
				
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = false;
		$expected = false;
		
		$actual = Util::toBoolean($input);
				
		self::assertEqual($actual, $expected);
	}
	
	public function test_05_quote(){
		//===============================================================
		$input = '&<>"\'';
		$expected = "&amp;&lt;&gt;&quot;&#039;";
		
		$actual = Util::quote($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = array('&<>"\'','&<>"\'');
		$expected = array("&amp;&lt;&gt;&quot;&#039;", "&amp;&lt;&gt;&quot;&#039;");
		
		$actual = Util::quote($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = $this;
		$expected = $this;
		
		$actual = Util::quote($input);
		
		self::assertEqual($actual, $expected);
	}
	
	public function test_06_substrWords(){
		//===============================================================
		$inputString = "word1 word2 word3 word4";
		$inputLength = 25;
		
		$expected = "word1 word2 word3 word4";
		
		$actual = Util::substrWords($inputString, $inputLength);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputString = "word1 word2 word3 word4";
		$inputLength = 25;
		$inputSuffix = "---";
				
		$expected = "word1 word2 word3 word4";
		
		$actual = Util::substrWords($inputString, $inputLength, $inputSuffix);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputString = "word1 word2 word3 word4 word5";
		$inputLength = 25;
				
		$expected = "word1 word2 word3 word4 ...";
		
		$actual = Util::substrWords($inputString, $inputLength);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputString = "word1 word2 word3 word4 word5";
		$inputLength = 25;
		$inputSuffix = "---";
				
		$expected = "word1 word2 word3 word4 ---";
		
		$actual = Util::substrWords($inputString, $inputLength, $inputSuffix);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$inputString = $this;
		$inputLength = 25;
		
		try {
			Util::substrWords($inputString, $inputLength);
		}catch(Exception $e){
			self::assertInstanceOf($e, "Mvc_Exception_Warning");
			self::assertEqual($e->getMessage(), "strlen() expects parameter 1 to be string, object given");
		}
	}
	
	public function test_07_urlEncode(){
		//===============================================================
		$input = 'http://www.google.nl/?s=Query&i=android&special=ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞàáâãäåçèéêëìíîïðñòóôõöøùúûüýÿþŔŕ&entities=<">\'';
		$expected = "http-www-google-nl-rs-query-i-android-special-aaaaaaceeeeiiiidnoooooouuuuybaaaaaaceeeeiiiidnoooooouuuuyybrr-entities";
		
		$actual = Util::urlEncode($input);
		
		self::assertEqual($actual, $expected);
		
		//===============================================================
		$input = $this;
		
		try{
			Util::urlEncode($input);
		}catch(Exception $e){
			self::assertInstanceOf($e, "Mvc_Exception_Warning");
			self::assertEqual($e->getMessage(), "html_entity_decode() expects parameter 1 to be string, object given");
		}
	}
	
	public function test_08_getMicrotime(){
		//===============================================================
		$microtimeStub = new TsT_stubbed_Microtime(0, 0.1);
		Util::$microtime = $microtimeStub;
		
		for($i = 0.1; $i<1; $i+=0.1){
			self::assertEqual(Util::getMicrotime(), $i);
		}
	}
	
	public function test_09_ksorti(){
		//===============================================================
		$input = array("a2" => "a2", "b2" => "b2", "b1" => "b1", "a1" => "a1", "a10" => "a10");
		$expected = array (  'a1' => 'a1',  'a10' => 'a10',  'a2' => 'a2',  'b1' => 'b1',  'b2' => 'b2');
		
		$actual = Util::ksorti($input);
		
		self::assertEqual($input, $expected);
		
		//===============================================================
		$input = $this;
		$expected = $this;
		
		try{
			$actual = Util::ksorti($input);
		}catch(Exception $e){
			self::assertInstanceOf($e, "Mvc_Exception");
			self::assertEqual($e->getMessage(), "Argument 1 passed to Util::ksorti() must be an array, object given, called in C:\\xampp\\private\\library\\TsT\\UtilTester.php on line 298 and defined");
		}
		
		self::assertEqual($input, $expected);
	}
	
	public function test_10_baseEncode(){
		$input = "";
		$expected = "";
		
		$actual = Util::base64UrlDecode($input);
	}
	
	public function test_11_baseDecode(){
		$input = "";
		$expected = "";
		
		$actual = Util::base64UrlDecode($input);
	}
}

return new UtilTester();